﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FactoryAndStrategy
{
    public class DeductionFacade
    {
        /// <summary>
        /// 對外公佈的扣款信息
        /// </summary>
        /// <param name="card"></param>
        /// <param name="trade"></param>
        /// <returns></returns>
        public static Card deduct(Card card, Trade trade) {
            //獲取消費策略
            StrategyMan reg = getDeductionType(trade);
            //初始化一個消費策略對象
            IDeduction deduction = StrategyFactory.GetDeduction(reg);
            //產生一個策略上下文
            DeductionContext context = new DeductionContext(deduction);
            //進行扣款處理
            context.exec(card, trade);
            //返回扣款處理完畢后的數據
            return card;

        }

        /// <summary>
        /// 獲取對應的商戶消費策略
        /// </summary>
        /// <param name="trade"></param>
        /// <returns></returns>
        public static StrategyMan getDeductionType(Trade trade)
        {
            //模擬操作
            if (trade.TradeNo.Contains("abc"))
            {
                return StrategyMan.FreeDeduction;
            }
            else {
                return StrategyMan.SteadyDeduction;
            }
        }
    }
}
